<template>
	<view>
		<image class="samePar bodyBg posAbso ltzero" src="../../static/images/login/loginBg.png"></image>
		<view class="titWrap">
			<view class="bigTit">你好!</view>
			<view class="smTit">欢迎进入社会心理服务云平台</view>
		</view>
		<view class="formWrap">
			<view class="formItem">
				<view class="itemTit">账号</view>
				<view class="itemCon">
					<image class="itemIcon" src="../../static/images/login/acc.png"></image>
					<input class="input" v-model="account" type="tel" placeholder="请输入身份证号" placeholder-style="font-weight:normal;color:#D2D3D8;"/>
				</view>
			</view>
			<view class="formItem">
				<view class="itemTit">密码</view>
				<view class="itemCon">
					<image class="itemIcon" src="../../static/images/login/password.png"></image>
					<input class="input" v-model="password" type="password" placeholder="请输入密码" placeholder-style="font-weight:normal;color:#D2D3D8;"/>
				</view>
			</view>
			<button class="comBtn" :disabled="isDisabled" @tap="goLogin">{{btnTit}}</button>
			<!-- <view class="forget">忘记密码</view> -->
		</view>
	</view>
</template>

<script>
	import { zzLogin } from '@/api/index/index'
	export default {
		data(){
			return{
				account:'',
				password:'',
				isDisabled:false,
				btnTit:'登录',
				loginNum :0//0上个页面不刷新 1刷新
			}
		},
		onLoad(option){
			this.loginNum = Number(option.loginNum)
		},
		methods:{
			goLogin(){
				if(this.account == ''){
					this.util.showToast('请输入身份证号');
				}else if(this.password == ''){
					this.util.showToast('请输入密码');
				}else{
					this.commonAccLogin();
				}
			},
			commonAccLogin(){
				uni.showLoading({ title: '登录中...', mask: true });
				this.btnTit = '登录中...';
				var field = {account:this.account,password:this.password};
				this.isDisabled = true;
				zzLogin(field).then(res=>{
					uni.showToast({ title: '登录成功' });
					var tmpRes = res.data.datas;
					uni.setStorageSync("token", tmpRes.token);
					uni.setStorageSync("userIdZz",tmpRes.userId);
					uni.setStorageSync("userSex",tmpRes.userSex);
					uni.setStorageSync('roleName',tmpRes.roleName);
					uni.setStorageSync('cityList',tmpRes.cityList);
					if(tmpRes.cityList.length == 1 && tmpRes.cityList[0].villageList.length == 1){
						uni.setStorageSync('setCity',tmpRes.cityList);
					}
					this.$store.commit('user/SET_SYLOADNUM',1);
					setTimeout(()=>{
						// 返回上一步
						if(this.loginNum == 0){
							uni.navigateBack({delta:1})
						}else{
							let pages = getCurrentPages();
							let prevPage = pages[pages.length - 2];
							prevPage.$vm.isRefreshFlag = true;
							uni.navigateBack({ delta: 1 });
						}
					},1500);
				}).catch(err=>{
					this.isDisabled = false;
					this.btnTit = '登录';
					console.log(err)
				});
			}
		}
	}
</script>

<style lang="scss">
	$blue:#0655E0;
	.titWrap{
		width: 550rpx;
		margin: 0 auto;
		padding: 80rpx 0 50rpx;
		color: $blue;
		font-weight: 600;
		.bigTit{
			margin-bottom: 20rpx;
			font-size: 50rpx;
		}
		.smTit{
			font-size: 36rpx;
		}
	}
	.formWrap{
		width: 600rpx;
		margin:30rpx auto 0;
		--sonHei:90rpx;
		--indent:20rpx;
		.forget{
			text-align: right;
			color: $pss-color-blueDeep;
			font-size: 26rpx;
			padding: 20rpx 0;
		}
		.comBtn{
			background: $pss-color-blueDeep;
			border-radius: 50rpx;
			margin-top: 100rpx;
			font-size: 32rpx;
			box-shadow: 0 20rpx 20rpx rgba(79, 132, 224, 0.3);
		}
		.formItem{
			&:first-child{
				margin-bottom: 30rpx;
			}
			.itemTit{
				font-size: 30rpx;
				color: #90A3C3;
				margin-bottom: 15rpx;
				text-indent: var(--indent);
			}
			.itemCon{
				height: var(--sonHei);
				border-radius: 8rpx;
				background: #fff;
				padding: 0 var(--indent);
				display: flex;
				align-items: center;
				.itemIcon{
					width: 40rpx;
					height: 40rpx;
					margin-right: var(--indent);
				}
				.input{
					flex: 1;
					height: 100%;
					font-size: 28rpx;
					font-weight: bold;
					color: $pss-text-color0;
				}
			}
		}
	}
	page{
		height: 100%;
		position: relative;
	}
	.bodyBg{
		z-index: -1;
	}
</style>